package comchifaner.util;

import java.util.LinkedHashMap;

public class PageUtil {
	
	public static Integer PAGE_SIZE=10;//每页展示记录数
	

	/**
	 * totalCount 总记录数 pageNum 当前页数
	 * Title: PageUtil.java<br>
	 * Description: <br>
	 * @author tao.zhang
	 * @createDate 2016年3月12日
	 */
	public PageUtil(Integer totalCount,Integer pn) {
		super();
		this.setPageNum(pn);
		this.setTotalCount(totalCount);
		totalPage(totalCount);
	}
	
	private Integer totalCount=0;//总条数
	
	private Integer totalPage=0;//总页数

	private Integer pageNum=0;

	
	public Integer getPageNum() {
		return pageNum;
	}

	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	
	
	public  Integer totalPage(Integer count){
		int total = 1 ;
		if(count > 0){
			if(count % PAGE_SIZE > 0 ){ 
				total = (count / PAGE_SIZE) + 1;
			}else {
				total = (count / PAGE_SIZE);
			} 
		}
		this.setPageNum(getPageNum());
		this.setTotalPage(total);
		return total;
	}
	
	
	public LinkedHashMap<String,Integer> getPageMap(){
		LinkedHashMap<String,Integer> map= new LinkedHashMap<String,Integer>();
		if(pageNum.equals(0)){this.setPageNum(1);}
		map.put("pageNum", this.getPageNum());
		map.put("pageSize", PAGE_SIZE);
		map.put("totalCount", this.getTotalCount());
		map.put("totalPage", this.getTotalPage());
		return map;
	}
	
	
}
